<?php
  
  class product_svc {
    
    public static function find_products($product_regex) {
   
      $q = " 
      select 
        p.description 
      from product p 
      where p.description regexp '" . $product_regex . "' 
      limit 0, 10;";

      mysql_connect("localhost", "root", "password") or die( mysql_error() );
      mysql_select_db("overall_pos_db") or die( mysql_error() );

      $r = mysql_query($q) or die( mysql_error() );
      $n = mysql_numrows($r);

      for( $i = 0; $i < $n; $i++ ) {
        $e = mysql_fetch_assoc($r);
        $o[] = $e;
      }

      return json_encode($o);

    }

  }


  print( product_svc::find_products($_REQUEST['product_regex']) );

?>
